package com.liulei.controller;

import com.liulei.entities.Salary;
import com.liulei.service.SalaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@RequestMapping("/salary")
@Controller
@Slf4j

public class SalaryController {
    /**
     * 自动装配计算工资业务逻辑
     */
    @Autowired
    private SalaryService salaryService;
    /**
     * 点击“计算工资”按钮，查询所有送水工的工资，然后将工资渲染到前端页面，并返回
     * @param model
     * @return 计算工资列表页面
     */
    @RequestMapping("/clacSalary")
    public String calcWorkerSalary(Model model) {
        List<Salary> salaryList = salaryService.listCalcSalary();
        model.addAttribute("salaryList",salaryList);
        return "salaryList";
    }

    @RequestMapping("/searchCalcSalary")
    public String searchCalcWorkerSalary(String startDate,String endDate,Model model) {
        List<Salary> salaryList = salaryService.calcSalaryByCondition(startDate, endDate);
        model.addAttribute("salaryList",salaryList);
        model.addAttribute("startDate",startDate);
        model.addAttribute("endDate",endDate);
        return "salaryList";
    }
}
